let chartObj2 = null;
const loadUserChartData2 = function (type = 'day') {
    $.get('admin/user-access-count?type=' + type, function (res) {
        if (res.code != 0) {
            return;
        }
        if (chartObj2 == null) {
            chartObj2 = echarts.init(document.getElementById('chart2'));
        }

        let option = {
            color:['#a87fd5','#60a881'],
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['老用户', '新用户']
            },
            grid: {
                left: '2%',
                right: '2%',
                bottom: '12%',
                top:'20%',
                containLabel: true
            },
            toolbox: {
                feature: {}
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: res.x_data
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '老用户',
                    type: 'bar',
                    smooth:true,
                    stack: 'one',
                    barWidth:'14px',
                    data: res.y_data['old_user_count'],
                },
                {
                    name: '新用户',
                    type: 'bar',
                    smooth:true,
                    stack: 'one',
                    barWidth:'14px',
                    data: res.y_data['new_user_count'],
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        chartObj2.setOption(option);
        window.addEventListener("resize", function () {
            chartObj2.resize();
        });
    });
}
loadUserChartData2();
